
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'
// import store from '@/store'
// 动态路由表
// export const asyncRoutes = [

// ]
export const routes = [

    {
        includes : ['hive','data'],
        path: '/Reg',
        component: Layout,
        meta: { title: '用户管理', roles: ['admin'] },
        children: [
            {
                includes : ['hive','data'],
                path: 'Registration',
                component: () => import('@/views/Registration/index.vue'),
                meta: { title: '用户注册' }
            },
            {
                includes : ['hive','data'],
                path: 'staff',
                component: () => import('@/views/staff/index.vue'),
                meta: { title: '员工管理' }
            },
            {
                includes : ['hive','data'],
                path: 'coupon',
                component: () => import('@/views/staff/components/coupon.vue'),
                meta: { title: '优惠卷' }
            },
            {
                includes : ['hive','data'],
                path: 'email',
                component: () => import('@/views/staff/components/email.vue'),
                meta: { title: '用户Email' }
            }
        ]
    },
    {
        path: '/login',
        component: () => import('@/views/Login/index'),
        hidden: true
    },
    {
        path: '/',
        component: Layout
        // redirect: '/Reg/Registration'
    },
    {
        includes : ['hive'],
        path: '/account',
        component: Layout,
        meta: { title: '账号信息' },
        children: [
            {
                includes : ['hive'],
                path: 'Tradingacct',
                component: () => import('@/views/Tradingacct/index.vue'),
                meta: { title: '交易账号' }
            },
            {
                includes : ['hive'],
                path: 'Tradingacct2',
                component: () => import('@/views/Tradingacct2/index.vue'),
                meta: { title: '账号历史' }
            },
            {
                includes : ['hive'],
                path: 'paying',
                component: () => import('@/views/paying/index.vue'),
                meta: { title: '收费账号' }
            }
        ]
    },
    {
        includes : ['hive'],
        path: '/distributed',
        component: Layout,
        meta: { title: '风控中心' },
        children: [
            {
                includes : ['hive'],
                path: 'distr',
                component: () => import('@/views/distributed/index.vue'),
                meta: { title: '账号监控' }
            },
            {
                includes : ['hive'],
                path: "history",
                component: () => import("@/views/distributed/components/history.vue"),
                meta: { title: '交易历史' }
            }
        ]
    },
    {
        includes : ['hive'],
        path: '/assess',
        component: Layout,
        meta: { title: '考核主题' },
        children: [
            {
                includes : ['hive'],
                path: 'challenge',
                component: () => import('@/views/assessment/components/challenge.vue'),
                meta: { title: '挑战申请' }
            },
            {
                includes : ['hive'],
                path: 'assessment',
                component: () => import('@/views/assessment/index.vue'),
                meta: { title: '挑战列表' }
            },
            {
                includes : ['hive'],
                path: 'contest',
                component: () => import('@/views/assessment/components/contest.vue'),
                meta: { title: '比赛设置' }
            },
        ]
    },
    {
        includes : ['hive'],
        path: '/Profit',
        component: Layout,
        meta: { title: '财务主题' },
        children: [
            {
                includes : ['hive'],
                path: 'refundList',
                component: () => import('@/views/Profit/refundList.vue'),
                meta: { title: '盈利申请' }
            },
            {
                includes : ['hive'],
                path: 'Profitlist',
                component: () => import('@/views/Profit/Profitlist.vue'),
                meta: { title: '退款申请' }
            },
            {
                includes : ['hive'],
                path: 'payList',
                component: () => import('@/views/Profit/payList.vue'),
                meta: { title: '缴费记录' }
            },
            {
                includes : ['hive'],
                path: 'confirm',
                component: () => import('@/views/Profit/confirm.vue'),
                meta: { title: '加密货币' }
            }
        ]
    },
    // 联盟计划
    {
        includes : ['hive'],
        path: '/promotion',
        component: Layout,
        meta: { title: '联盟计划' },
        children: [
            {
                includes : ['hive'],
                path: 'prom',
                component: () => import('@/views/promotion/index.vue'),
                meta: { title: '联盟计划' }
            },
            {
                includes : ['hive'],
                path: 'prom-payout',
                component: () => import('@/views/promotion/components/rewards.vue'),
                meta: { title: '奖金申请' }
            },
            {
                includes : ['hive'],
                path: 'prom-invite',
                component: () => import('@/views/promotion/components/invite.vue'),
                meta: { title: '邀请数据' }
            }
        ]
    },
    {
        includes : ['hive'],
        path: "/shop",
        component: Layout,
        meta: { title: '商城主题' },
        children: [

            {
                includes : ['hive'],
                path: "shopList",
                component: () => import("@/views/shop/index.vue"),
                meta: { title: '商城' }
            }
        ]
    },
    {
        includes : ['hive'],
        path: "/con",
        component: Layout,
        meta: { title: "交易中心" },
        children: [
            {
                includes : ['hive'],
                path: "history",
                component: () => import("@/views/distributed/components/history.vue"),
                meta: { title: '历史订单' }
            },
            {
                includes : ['hive'],
                path: "take",
                component: () => import("@/views/distributed/components/take.vue"),
                meta: { title: '持仓订单' }
            },
            {
                includes : ['hive'],
                path: "userH",
                component: () => import("@/views/distributed/components/userH.vue"),
                meta: { title: '账户数据' }
            }
        ]
    },
    {
        includes : ['data'],
        path: "/dataEntry",
        component: Layout,
        meta: { title: '数据录入' },
        children: [

            {
                includes : ['data'],
                path: "commodityExchange",
                component: () => import("@/views/dataEntry/commodityExchange/commodityExchangeIndex.vue"),
                meta: { title: '商品交易所' }
            }
        ]
    },
    {
        includes : ['config'],
        path: "/config",
        component: Layout,
        meta: { title: '数据' },
        children: [

            {
                includes : ['config'],
                path: "supplierAndData",
                component: () => import("@/views/config/supplier/supplierAndDataIndex.vue"),
                meta: { title: '数据源和数据' }
            },
            {
                includes : ['config'],
                path: "img",
                component: () => import("@/views/config/img/imgIndex.vue"),
                meta: { title: '图片管理' }
            },
        ]
    },
    // {
    //   path: '/withd',
    //   component: Layout,
    //   meta: { title: '提现申请' },
    //   children: [
    //     {
    //       path: 'withdrawal',
    //       component: () => import('@/views/withdrawal/index.vue'),
    //       meta: { title: '提现申请' }
    //     }
    //   ]
    // },
    {
        path: '/404',
        component: () => import('@/views/404'),
        hidden: true
    }
]

const createRouter = () =>
    new Router({
        mode: 'history',
        scrollBehavior: () => ({ y: 0 }),
        routes: routes
    })

const router = createRouter()

// 重置路由方法
export function resetRouter() {
    // 得到一个全新的router实例对象
    const newRouter = createRouter()
    // 使用新的路由记录覆盖掉老的路由记录
    router.matcher = newRouter.matcher
}

// const whiteList = ['/login', '/404']
// router.beforeEach((to, from, next) => {
//   // store.getters.token
//   const token = store.getters.token
//   // console.log(token, 'token')
//   const token1 = store.getters.whetherItIsAdmin
//   // console.log(token1, 'tokenq')
//   if (token) {
//     if (to.path === '/login') {
//       next('/') // 跳转到主页
//     } else {
//       if (token1 === 0) {
//         if (to.path === '/') {
//           next('/account/Tradingacct')
//         }
//         const filterRoutes = routes.filter(router => router.path !== '/Reg')
//         store.commit('user/setMenuList', filterRoutes)
//       } else if (token1 === 1) {
//         if (to.path === '/') {
//           next('/Reg/Registration')
//         }
//         store.commit('user/setMenuList', routes)
//       }
//       next() // 放行
//     }
//   } else {
//     if (whiteList.includes(to.path)) {
//       next()
//     } else {
//       next('/login') // 跳转到登录页
//     }
//   }
// })

export default router
